import 'package:flutter/material.dart';
import 'package:mall/core/models/logistics.dart';
import 'package:mall/core/models/order_detail.dart';
import 'package:mall/core/providers/pages/mine/order/logistics_model.dart';
import 'package:mall/core/providers/view_model.dart';
import 'package:provider/provider.dart';

class LogisticsPage extends StatelessWidget {
  static const routeName = '/LogisticsPage';
  final Invoice args;

  LogisticsPage({
    Key key,
    @required this.args,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (context) => LogisticsModel(Provider.of(context, listen: false), args),
      child: Scaffold(
        appBar: AppBar(
          title: Text('物流信息'),
        ),
        body: Consumer<LogisticsModel>(
          builder: (context, model, child) {
            switch (model.viewState) {
              case ViewState.busy:
                return Center(
                  child: CircularProgressIndicator(),
                );
              case ViewState.error:
                return Center(
                  child: Text(model.errorMessage),
                );
              case ViewState.success:
                return _BodyWidget();
              default:
                return Container();
            }
          },
          child: Container(),
        ),
      ),
    );
  }
}

class _BodyWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    LogisticsModel model = Provider.of(context, listen: false);
    Logistics logistics = model.logistics;
    return ListView.builder(
      itemBuilder: (context, index) {
        Trace trace = logistics.traces[index];
        return ListTile(
          title: Text(trace.acceptStation),
          subtitle: Text(trace.acceptTime),
        );
      },
      itemCount: logistics.traces.length,
    );
  }
}
